<form class="layui-form pt10" action="{:url('kgkd')}" method="post" id="editForm" >
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">会员</label>
            <div class="layui-input-inline">
                <select name="user_id" class="layui-input field-user_id" disabled lay-verify="required" >
                  {$users|raw}
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">操作单号</label>
            <div class="layui-input-inline">
                <input type="text"  class="layui-input field-sn" name="sn" readonly lay-verify="" autocomplete="off" ">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">库管</label>
            <div class="layui-input-inline">
                <select name="warehouse_admin" class="layui-input field-warehouse_admin" lay-verify="required" >
                  {$warehouse_admins|raw}
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >进度</label>
            <div class="layui-input-inline w200">
                <input type="radio" class="field-status" name="status" value="0" title="回退顾问">
                <input type="radio" class="field-status" name="status" value="1" title="库管配料" checked>
                <input type="radio" class="field-status" name="status" value="2" title="收银结算">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >确认配料</label>
        <div class="layui-input-block">
            <textarea name="products" readonly id="products" rows="8" cols="80"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" class="field-id" name="id">
            <input type="hidden" class="field-warehouse_admin" name="warehouse_admin" value="{:ADMIN_ID}">
        </div>
    </div>
    <div class="pop-bottom-bar hisi-footer">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: true}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>配料单</legend>
</fieldset>
<table id="dataTable" lay-filter="dataTable"></table>
<!-- <script src="__PUBLIC_JS__/layui/xm-select.js" charset="utf-8"></script> -->
{include file="system@block/layui" /}
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('Subscribe/editProduct')}?product_id={{ d.product_id }}&sub_id={{ d.sub_id }}&project_id={{ d.project_id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '800px', height: '600px', title: '修改'}" >修改</a>

    <a href="{:url('Subscribe/delProduct')}?product_id={{ d.product_id }}&sub_id={{ d.sub_id }}&project_id={{ d.project_id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>
<script id="toolbar" type="text/html">
   <!-- <a href="{:url('Subscribe/addProduct')}?sub_id={{d.sub_id}}&project_id={{ d.project_id }}" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '800px', height: '600px', title: '添加'}">&nbsp;添加</a> -->
   <button class="layui-btn cc" onclick="">选取配料</button>
</script>
<script>

layui.use(['func','laydate','table','jquery'], function() {
    //常规用法
    var laydate = layui.laydate;
    laydate.render({
          elem: '#date',
          trigger:'click',
          type:'datetime'
        });
    layui.func.assign({:json_encode($formData)});

    var table = layui.table;
    var $ = layui.jquery;
     $(document).on('click','.cc',function(){
         var checkStatus = table.checkStatus('dataTable')
         ,data = checkStatus.data;
         // $('#products').val(data);
         $('#products').val(JSON.stringify(data));
         // layer.alert(JSON.stringify(data));
     })

    table.render({
        elem: '#dataTable'
        ,url: '{:url('getTempProduct')}?sub_id={$formData['id']}' //数据接口
        ,page: true //开启分页
        ,skin: 'row'
        ,even: true
        ,limit: 30
        ,text: {
            none : '暂无相关数据'
        }
        ,toolbar: '#toolbar'
        ,defaultToolbar: ['filter']
        ,cols: [[ //表头
            {type:'checkbox'}
            ,{field: 'project_name', title: '项目名称',templet:function(d){
                return d.project_name + ' * ' + d.project_num
            }}
            // ,{field: 'project_num', title: '项目数量'}
            ,{field: 'product_name', title: '配料名称'}
            ,{field: 'product_num', title: '配料数量'}
            ,{field: 'danwei', title: '单位',templet:function(d){
                if(d.is_volume ==1){
                    return d.decomposition
                }else{
                    return d.unit
                }
            }}
            ,{field: 'is_volume', title: '是否分解',templet:function(d){
                if(d.is_volume ==1){
                    return '分解使用';
                }else{
                    return '不分解';
                }
            }}
            ,{field: 'num', title: '仓库',templet:function(d){
                var warehouse = {:json_encode($warehouse)};

                if(d.is_volume == 1){
                    for (var i = 0; i < warehouse.length; i++) {
                        if(warehouse[i].type == 1){
                            return warehouse[i].name
                        }
                    }
                }else{
                    for (var i = 0; i < warehouse.length; i++) {
                        if(warehouse[i].type == 0){
                            return warehouse[i].name
                        }
                    }
                }
            }}
            ,{title: '操作', toolbar: '#buttonTpl'}
            ]]
            ,done: function(){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
            }
        });

        //监听工具条
        table.on('tool(dataTable)', function(obj){
            // alert(1)
          var data = obj.data;
          if(obj.event === 'detail'){
            layer.msg('ID：'+ data.id + ' 的查看操作');
          } else if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
              obj.del();
              layer.close(index);
            });
          } else if(obj.event === 'edit'){
            layer.alert('编辑行：<br>'+ JSON.stringify(data))
          }
        });
});
</script>
